﻿namespace FormCreator.ViewModel
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Reflection;
    using System.Text;

    /// <summary>
    /// This class represents an object's property and its value.
    /// </summary>
    public class PropertyValueItem
    {
        /// <summary>
        /// The element.
        /// </summary>
        private object element;

        /// <summary>
        /// The displayed property.
        /// </summary>
        private PropertyInfo property;

        /// <summary>
        /// Initializes a new instance of the <see cref="PropertyValueItem" /> class.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="property">The property.</param>
        public PropertyValueItem(object element, PropertyInfo property)
        {
            this.element = element;
            this.property = property;
        }

        /// <summary>
        /// Gets the name of the property.
        /// </summary>        
        public string Name
        {
            get
            {
                return this.property.Name;
            }
        }

        /// <summary>
        /// Gets or sets the value associated with the property.
        /// </summary>
        public string Value
        {
            get
            {
                return this.property.GetValue(this.element, null) as string;
            }

            set
            {
                this.property.SetValue(this.element, value, null);
            }
        }
    }
}
